<template>
  <div>
    <el-container>
      <el-header class="homeHeader">
        <div class="title">云 E 办</div>
        <el-dropdown @command="handleCommand" class="userInfo">
          <span class="el-dropdown-link">{{user.name}}<i><img src="./haha.jpg"></img></i></span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="userinfo">个人中心</el-dropdown-item>
            <el-dropdown-item command="setting">设置中心</el-dropdown-item>
            <el-dropdown-item command="logout">注销</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <el-menu class="el-menu-vertical-demo" router unique-opened>
            <el-submenu :index="index + ''" v-for="(item, index) in routes" v-if="!item.hidden" :key="index">
              <template #title>
                <i :class="item.iconCls"></i>
                <span>{{ item.name }}</span>
              </template>
              <el-menu-item :index="children.path" v-for="(children, index2) in item.children">{{ children.name }}</el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <template>
            <el-breadcrumb separator-class="el-icon-arrow-right" v-if="this.$router.currentRoute.path!='/home'">
              <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
              <el-breadcrumb-item><a href="/">{{this.$router.currentRoute.name}}</a></el-breadcrumb-item>
            </el-breadcrumb>
          </template>
          <div class="homeWelcome" v-if="this.$router.currentRoute.path=='/home'">欢迎来到云E办</div>
          <router-view class="homeRouterView"></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data () {
    return {
      user: JSON.parse(window.sessionStorage.getItem('user'))
    }
  },
  created () {
     
  },
  methods: {
    menClick (index) {
      this.$router.push(index)
    },
    handleCommand(command) {
        if (command == 'logout'){
          this.$confirm('此操作将退出登录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.postRequest('/logout').then(resp => {
          })
          window.sessionStorage.removeItem('tokenStr')
          window.sessionStorage.removeItem('user')
          this.$store.commit('initRoutes', [])
          this.$router.replace('/')
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消注销'
          });
        });
          
        }
      }
  },
  computed: {
    routes () {
      return this.$store.state.routes;
    }
  }
}
</script>

<style scoped>
.fa {
  margin-right: 8px;
}
.homeHeader {
  background-color: #409eff;
  justify-content: space-between;
  align-items: center;
  display: flex;
  /* box-sizing: border-box; */
  padding: 0 15px;
}
.title {
  font-size: 30px;
  font-family: 楷体;
  color: #fff;
}
.homeHeader .userInfo {
  cursor: pointer;
}
.el-dropdown-link {
  display: flex;
  align-items: center;
  color: #fff;
  margin-left: 3px;
}
.el-dropdown-link img {
  width: 48px;
  height: 48px;
  border-radius: 24px;
  margin-left: 5px;
}
.homeWelcome {
  text-align: center;
  font-size: 30px;
  font-family: 华文楷体;
  color: #409eff;
  padding-top: 50px;
}
.homeRouterView {
  margin-top: 15px;
}
</style>
